﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar;

namespace KP_CommonLibrary.KP_CommonControls
{
    #region KP_TextBox
    public class KP_TextBox : TextBoxX
    {
        public string ToolTipButton1 { get; set; }
        public string ToolTipButton2 { get; set; }
        private SuperTooltip _Tooltip;
        public SuperTooltip TooltipController
        {
            get
            {


                return _Tooltip;
            }
            set
            {
                _Tooltip = value;

            }
        }
        public KP_TextBox()
        {
            base.Size = new Size(80, 25);
            //base.Font = KP_UIConfig.EditControlFont;
            base.BackColor = System.Drawing.Color.White;
            base.ForeColor = System.Drawing.Color.Navy;
            VisibleChanged += new EventHandler(KP_TextBox_VisibleChanged);
            
        }

        void KP_TextBox_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
                Font = KP_UIConfig.EditControlFont;
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
                TooltipController = null;
            base.Dispose(disposing);
        }
        bool hasShow1 = false, hasShow2 = false;
        protected override void OnMouseMove(MouseEventArgs e)
        {

            if (TooltipController != null)
            {

                bool b1 = MouseMoveButton1(e);
                bool b2 = MouseMoveButton2(e);
                SuperTooltipInfo si = EnsureTooltip();
                if (!b1 && !b2)
                {
                    if (hasShow1 || hasShow2)
                    {
                        hasShow1 = false;
                        hasShow2 = false;
                        si.BodyText = "";
                        TooltipController.HideTooltip();
                    }
                }
                if (b1)
                {
                    if (!hasShow1 && !string.IsNullOrEmpty(ToolTipButton1))
                    {
                        hasShow1 = true;
                        si.BodyText = ToolTipButton1;
                        TooltipController.ShowTooltip(this);
                    }
                }
                else
                    hasShow1 = false;
                if (b2)
                {
                    if (!hasShow2 && !string.IsNullOrEmpty(ToolTipButton1))
                    {
                        hasShow2 = true;
                        si.BodyText = ToolTipButton2;
                        TooltipController.ShowTooltip(this);
                    }
                }
                else
                    hasShow2 = false;
            }
            base.OnMouseMove(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            if (TooltipController != null)
                TooltipController.HideTooltip();
            base.OnMouseLeave(e);
        }
        SuperTooltipInfo EnsureTooltip()
        {
            SuperTooltipInfo si = TooltipController.GetSuperTooltip(this);
            if (si == null)
            {
                si = new SuperTooltipInfo();
                TooltipController.SetSuperTooltip(this, si);
            }
            return si;


        }
        bool MouseMoveButton1(MouseEventArgs e)
        {
            return ButtonCustom != null
                && ButtonCustom.Visible
                && ButtonCustom.ItemReference.RenderBounds.Contains(e.X, e.Y);

        }
        bool MouseMoveButton2(MouseEventArgs e)
        {
            return ButtonCustom2 != null
                && ButtonCustom2.Visible
                && ButtonCustom2.ItemReference.RenderBounds.Contains(e.X, e.Y);

        }
        
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.ResumeLayout(false);
        }
    }
    #endregion
}
